package com.ruoyi.chat.controller;

import java.util.List;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.chat.domain.ManageLlm;
import com.ruoyi.chat.service.IManageLlmService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;

/**
 * 大模型管理Controller
 *
 * @author waky
 * @date 2025-04-10
 */
@Tag(name = "大模型管理接口")
@RestController
@RequestMapping("/llm/manage")
public class ManageLlmController extends BaseController
{
    @Autowired
    private IManageLlmService manageLlmService;

    @Operation(summary = "查询大模型管理列表")
    @PreAuthorize("@ss.hasPermi('llm:llm:list')")
    @GetMapping("/list")
    public TableDataInfo list(ManageLlm manageLlm)
    {
        startPage();
        List<ManageLlm> list = manageLlmService.selectManageLlmList(manageLlm);
        return getDataTable(list);
    }

    @Operation(summary = "导出大模型信息列表")
    @PreAuthorize("@ss.hasPermi('llm:llm:export')")
    @Log(title = "大模型管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ManageLlm manageLlm)
    {
        List<ManageLlm> list = manageLlmService.selectManageLlmList(manageLlm);
        ExcelUtil<ManageLlm> util = new ExcelUtil<ManageLlm>(ManageLlm.class);
        util.exportExcel(response, list, "大模型管理数据");
    }

    @Operation(summary = "获取大模型管理详细信息")
    @PreAuthorize("@ss.hasPermi('llm:llm:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(manageLlmService.selectManageLlmById(id));
    }

    @Operation(summary = "新增大模型")
    @PreAuthorize("@ss.hasPermi('llm:llm:add')")
    @Log(title = "大模型管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ManageLlm manageLlm)
    {
        return toAjax(manageLlmService.insertManageLlm(manageLlm));
    }

    @Operation(summary = "修改大模型")
    @PreAuthorize("@ss.hasPermi('llm:llm:edit')")
    @Log(title = "大模型管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ManageLlm manageLlm)
    {
        return toAjax(manageLlmService.updateManageLlm(manageLlm));
    }

    @Operation(summary = "删除大模型")
    @PreAuthorize("@ss.hasPermi('llm:llm:remove')")
    @Log(title = "大模型管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(manageLlmService.deleteManageLlmByIds(ids));
    }
}
